package com.testxmlparse;
import java.util.List;

import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.XMLConfiguration;
import org.apache.commons.lang.exception.NestableException;

/***
 * 解析xml的类
 * 
 * 
 * **/
public class ParseXML {
  
  
  public static void main(String[] args) throws Exception{
     loadxml();
  }
  
  public  static void loadxml() throws Exception, NestableException{
  
     XMLConfiguration config = new XMLConfiguration();
   config.setDelimiterParsingDisabled(true);
		config.load("test.xml");
   //  XMLConfiguration config = new XMLConfiguration("com/nice/application.xml");

      
     //获取单个属性的值
     System.out.println(config.getString("person.id"));
     System.out.println(config.getString("person.name"));
     
     //System.out.println(config.getString("person.address"));
     
     //获取多个相同的标签值
     List<Object> list=config.getList("person.address");
     System.out.println(list);
     
     
     //获取属性的值, 注意写法
     //获取标签的值
     System.out.println(config.getString("person.info"));
     //获取属性的时间
     System.out.println(config.getString("person.info[@time]"));
     //获取属性的数量
     System.out.println(config.getString("person.info[@count]"));
     
     
     
     //获取多个属性的值的集合
     
     List<Object> attributes=config.getList("person.info[@time]");
     
     System.out.println("日期集合: "+attributes);
     
     
     List<Object> attributes2=config.getList("person.info[@count]");
     
     System.out.println("数量集合: "+attributes2);
     
     System.out.println(config.getRootNode().getName());
     
     config.load("CaCdkmtbAPI.nsql.xml");
     System.out.println(config.getString("description"));
    // System.out.println(config.get("dynamicSelect"));
     
  }

}